package com.timo.concurrent.chapter02;

/**
 * @Description: 如果在构造 Thread 的时候没有显示地指定一个 ThreadGroup，那么子线程将会被加入父线程所在的线程组
 * @Author: timo
 * @Date: 2019/10/12 17:20
 */
public class ThreadConstruction {
    public static void main(String[] args) {
        Thread t1 = new Thread("t1");

        ThreadGroup group = new ThreadGroup("TestGroup");

        Thread t2 = new Thread(group,"t2");
        ThreadGroup mainThreadGroup = Thread.currentThread().getThreadGroup();
        System.out.println("Main Thread belong group :" + mainThreadGroup.getName());
        System.out.println("t1 and main belong the same group :" + (mainThreadGroup == t1.getThreadGroup()));
        System.out.println("t2 thread group not belong main group :" + (mainThreadGroup == t2.getThreadGroup()));
        System.out.println("t2 thread group belong main TestGroup :"+(group == t2.getThreadGroup()));


    }
}

/* 注释
①创建了一个 Thread tl ，
②创建了一个 ThreadGroup，
③创建了一个 Thread t2 ， 并且将它加入到了 group 中 ，我们并没有给 tl 指定任何 Group
// out
Main Thread belong group :main
t1 and main belong the same group :true
t2 thread group not belong main group :false
t2 thread group belong main TestGroup :true
 */